﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SearchOperations.DAL;

namespace ClientSide
{
    public partial class frmdestinations : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddStartPoint.DataSource = BookOperations.GetAllSettlements(true);
                ddStartPoint.DataTextField = "SettlementName";
                ddStartPoint.DataValueField = "SettlementID";
                ddStartPoint.AutoPostBack = true;
                ddStartPoint.DataBind();
            }

            ddStartPoint.SelectedIndexChanged += new EventHandler(ddStartPoint_SelectedIndexChanged);
            //ddEndPoint.SelectedIndexChanged += new EventHandler(ddEndPoint_SelectedIndexChanged);
            //btnShow.Click += new EventHandler(btnShow_Click);

        }

        //void ddEndPoint_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    gvTravelDetails.Visible = false;
        //}

        //void btnShow_Click(object sender, EventArgs e)
        //{
        //    if (ddStartPoint.SelectedValue != string.Empty & ddEndPoint.SelectedValue != string.Empty)
        //    {
        //        lblRequired.Text = string.Empty;
        //        gvTravelDetails.Visible = true;
        //        string date = tbDate.Text;
        //        string[] dateArr = date.Split('/');
        //        DateTime tDate = new DateTime(int.Parse(dateArr[2]),
        //            int.Parse(dateArr[0]), int.Parse(dateArr[1]));

        //        gvTravelDetails.DataSource = BookOperations.GetRoutes
        //            (long.Parse(ddStartPoint.SelectedValue), long.Parse(ddEndPoint.SelectedValue),
        //            tDate);
        //        gvTravelDetails.DataBind();
        //    }
        //    else
        //    {
        //        lblRequired.Text = "Settlement required!";
        //    }
        //}

        void ddStartPoint_SelectedIndexChanged(object sender, EventArgs e)
        {
            //gvTravelDetails.Visible = false;
            ddEndPoint.DataSource = BookOperations.GetAllConnectedSettlements
                (long.Parse(ddStartPoint.SelectedValue));
            ddEndPoint.DataTextField = "SettlementName";
            ddEndPoint.DataValueField = "SettlementID";
            ddEndPoint.DataBind();
        }
    }
}
